public class Test {


    public static void main(String[] args) {
        int[] nums = {0, 1, 0, 3, 12};
        moveZeroes(nums);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + " ");
        }
    }

    public static void moveZeroes(int[] nums) {
        int desc = -1;
        for (int cur = 0; cur < nums.length; cur++) {
            if (nums[cur] != 0) {
                desc++;
                int tmp = nums[cur];
                nums[cur] = nums[desc];
                nums[desc] = tmp;
            }
        }
    }

    public void duplicateZeros1(int[] arr1) {
        int[] arr2 = new int[arr1.length];
        int dest = 0;
        int cur = 0;
        while (dest < arr2.length) {
            if (arr1[cur] != 0) {
                arr2[dest++] = arr1[cur++];
            } else {
                if (dest < arr2.length) {
                    arr2[dest++] = 0;
                }
                if (dest < arr2.length) {
                    arr2[dest++] = 0;
                }
                cur++;
            }
        }

        for (int i = 0; i < arr2.length; i++) {
            arr1[i] = arr2[i];
        }
    }


    public void duplicateZeros(int[] arr) {
        int cur = 0;
        int dest = 0;
        int size = arr.length;

        while (dest < size) {
            if (arr[cur] != 0) {
                dest++;
            } else {
                dest += 2;
            }
            if (dest - 1 >= size) {
                break;
            }
            cur++;
        }

        if (dest == size) {
            arr[size] = 0;
            dest -= 2;
            cur--;
        }
        while (cur >= 0) {
            if (arr[cur] != 0) {
                arr[dest] = arr[cur];
            } else {
                arr[dest--] = 0;
                arr[dest--] = 0;
            }
        }
    }


}
